package com.shenhaofeng.rxcache.source;

import android.support.v4.util.LruCache;

/**
 * 在内存中缓存的数据源,由{@link LruCache}实现
 * Created by haofeng on 2016/9/25.
 */

public class MemorySource<T> implements CacheSource<T> {


    private LruCache<String, T> mCache;


    /**
     * 创建新的缓存数据源实例
     * @param maxSize
     * 缓存上限
     */
    public MemorySource(int maxSize) {
        this.mCache = new LruCache<>(maxSize);
    }

    @Override
    public T get(String key) {
        return mCache.get(key);
    }

    @Override
    public boolean put(String key, T data) {
        mCache.put(key, data);
        return true;
    }
}
